package com.university.logistic.fileter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

@Component
@Order(1)
public class RoleGatewayFilterFactory extends AbstractGatewayFilterFactory<RoleGatewayFilterFactory.RoleConfig> {
    public RoleGatewayFilterFactory(){
        super(RoleConfig.class);
    }

    @Override
    public List<String> shortcutFieldOrder() {//指定参数顺序
        return Arrays.asList("name","role","state");
    }

    @Override
    public GatewayFilter apply(RoleConfig config) {
        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println("==========进入角色过滤===========");
                System.out.println(config.name+"=="+config.role+"=="+config.state);
                return null;
            }
        };
    }


    static public class RoleConfig{
        private String name;
        private String role;
        private Integer state;

        public String getName(){
            return this.name;
        }
        public String getRole(){
            return this.role;
        }

        public Integer getState(){
            return this.state;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setRole(String role) {
            this.role = role;
        }

        public void setState(Integer state) {
            this.state = state;
        }
    }
}
